﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Web.Old_App_Code;

public partial class backstage_admin_top : System.Web.UI.Page
{
    // Fields
    protected string accreditXmlPath = "/xml/accredit.xml";
    protected AdminGroupManager agm = new AdminGroupManager();
    protected DataEncryption de = new DataEncryption();
    protected SoftReg sr = new SoftReg();
    protected string xmlPath = "/xml/language_version.xml";

    // Methods
    protected StringBuilder AccreditBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if ((this.Session["admin_user"] == null) || (this.Session["language_version"] == null))
            {
                return builder;
            }
            string mNum = this.sr.getMNum();
            string str2 = this.sr.getRNumByMNum(mNum);
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.accreditXmlPath));
            XmlElement element = document.SelectSingleNode("accredit_set/machine_code") as XmlElement;
            XmlElement element2 = document.SelectSingleNode("accredit_set/authorization_code") as XmlElement;
            Admin admin = this.Session["admin_user"] as Admin;
            int num = Convert.ToInt32(this.agm.GetAdminGroupById(admin.GroupId).Rows[0]["isSupplier"]);
            if ((element2.GetAttribute("value") == str2) && (element.GetAttribute("value") == mNum))
            {
                switch (num)
                {
                    case 0:
                        builder.AppendLine("&nbsp;&nbsp;<b style=\"color:#009900; vertical-align:middle;\">正版授权</b>&nbsp;&nbsp;<input type=\"button\" style=\"margin-top:2px;\" class=\"formButton\" value=\"网站授权\" onclick=\"top.main.location='accredit.aspx';\" />");
                        return builder;

                    case 1:
                        builder.AppendLine("&nbsp;&nbsp;<b style=\"color:#009900; vertical-align:middle;\">正版授权</b>");
                        break;
                }
                return builder;
            }
            if (num == 0)
            {
                builder.AppendLine("&nbsp;&nbsp;<input type=\"button\" style=\"margin-top:2px;\" class=\"formButton\" value=\"网站授权\" onclick=\"top.main.location='accredit.aspx';\" />");
            }
        }
        catch
        {
        }
        return builder;
    }

    protected StringBuilder GetAdmin()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if ((this.Session["admin_user"] == null) || (this.Session["language_version"] == null))
            {
                return builder;
            }
            string attribute = "";
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.xmlPath));
            XmlNodeList childNodes = document.SelectSingleNode("language").ChildNodes;
            foreach (XmlNode node in childNodes)
            {
                XmlElement element = (XmlElement)node;
                if (element.GetAttribute("code") == this.Session["language_version"].ToString())
                {
                    attribute = element.GetAttribute("name");
                    break;
                }
            }
            builder.AppendLine("欢迎您，<b><a href=\"admin_set.aspx\">" + (this.Session["admin_user"] as Admin).UserName + "</a></b>，感谢您登录使用！语言版本：" + attribute);
        }
        catch
        {
        }
        return builder;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((this.Session["admin_user"] == null) && (this.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
    }

}